<?php

class LinhVuc_DanhMucService {

    public static function getDanhMucsByLinhVucId($Id) {
        return DanhMuc::model()->findAllByAttributes(array('LinhVucId' => $Id));
    }

    public static function getTenLinhVucById($Id) {
        $LinhVuc = LinhVuc::model()->findByPk($Id);
        return $LinhVuc->Ten;
    }

    public static function changeTenLinhVuc($Id, $Name) {
        return LinhVuc::model()->updateByPk($Id, array('Ten' => $Name));
    }

    public static function changeTenDanhMuc($Id, $Name) {
        return DanhMuc::model()->updateByPk($Id, array('Ten' => $Name));
    }

    public static function deleteLinhVuc($Id) {
        $linhvuc = LinhVuc::model()->findByPk($Id);
        if (count($linhvuc->getRelated('danhmucs')) != 0 ||  count($linhvuc->getRelated('nguoidungs')) != 0) {
            return false;
        } else {
            return $linhvuc->delete();
        }
    }

    public static function deleteDanhMuc($Id) {
        $danhmuc = DanhMuc::model()->findByPk($Id);
        if (count($danhmuc->getRelated('ytuongs')) != 0 ||  count($danhmuc->getRelated('nguoidungs')) != 0) {
            return false;
        } else {
            return $danhmuc->delete();
        }
    }

}
